<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title></title>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <link href="/static/css/font.css?v={{data.version}}" rel="stylesheet">
  <link href="/static/css/weadmin.css?v={{data.version}}" rel="stylesheet">
</head>

<body>
  <div class="weadmin-body">
    <form class="layui-form">

      <div class="layui-form-item">
        <label for="L_username" class="layui-form-label">
          <span class="we-red">*</span>用户名
        </label>
        <div class="layui-input-inline">
          <input type="text" name="username" lay-verify="required|nikename" autocomplete="off" class="layui-input">
        </div>

         <div style="line-height: 38px;">
          <a class="layui-btn layui-btn-sm" id="randUser" title="刷新">
          <i class="layui-icon layui-icon-refresh"></i>
          </a>
        </div>
      </div>

      <div class="layui-form-item">
        <label for="L_email" class="layui-form-label">
          <span class="we-red">*</span>密&nbsp;&nbsp;码
        </label>
        <div class="layui-input-inline">
          <input type="text" name="password" lay-verify="required" autocomplete="" class="layui-input">
        </div>

        <div style="line-height: 38px;">
          <a class="layui-btn layui-btn-sm" id="randPwd" title="刷新">
          <i class="layui-icon layui-icon-refresh"></i>
          </a>
        </div>
      </div>

      <div class="layui-form-item">
        <label for="L_email" class="layui-form-label">
          <span class="we-red">*</span>邮&nbsp;&nbsp;件
        </label>
        <div class="layui-input-inline">
          <input type="text" name="email" lay-verify="required" autocomplete="" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="L_repass" class="layui-form-label">
        </label>
        <button class="layui-btn" lay-filter="add" lay-submit="">确定</button>
      </div>
    </form>
  </div>
  <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
  <script src="/static/js/md5.js" charset="utf-8"></script>
  

  <script>

    function getUrlParam(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
      var r = window.location.search.substr(1).match(reg);  //匹配目标参数
      if (r != null) return unescape(r[2]); return null; //返回参数值
    }

    function randStr(len=4){
      var str = '';
      var chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789';
      var chrlen = chars.length - 1;
      for (var i =  0; i <= len; i++) {
        var random = Math.ceil(Math.random()*chrlen);
        str += chars[random];
      }
      return str
    }

    layui.extend({
      base: '/static/js/'
      , version: '1011001'
    });
    layui.use(['form', 'jquery', 'util', 'layer'], function () {
      var form = layui.form,
        $ = layui.jquery,
        util = layui.util,
        admin = layui.admin,
        layer = layui.layer;

      var vuser = randStr(5);
      var vpwd = randStr(10);
      // $("input[name='username']").val(vuser);
      // $("input[name='password']").val(vpwd);
      $('#randUser').click(function(){
          var v = randStr(5);
          $("input[name='username']").val(v);
      });

      $('#randPwd').click(function(){
          var v = randStr(10);
          $("input[name='password']").val(v);
      });

      $.getJSON('/user_api/get',{}, function(data){
        // console.log(data);
        $("input[name='username']").val(data['data'][0]['username']);
        $("input[name='password']").val(data['data'][0]['password']);
        $("input[name='email']").val(data['data'][0]['email']);
      });

      //监听提交
      form.on('submit(add)', function (data) {
        var f = data.field;
        $.post('/user_api/edit',f,function(data){
            data = $.parseJSON(data);
            layer.msg(data.msg);
            setTimeout(function(){
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                window.parent.window.location.reload();
            },2000);
        });
        return false;
      });

    });
  </script>
</body>

</html>